package ModelLayer;
import java.util.ArrayList;

/**
 * Write a description of class OrderTypeLib here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class OrderTypeLib
{
    // instance variables - replace the example below with your own
    private ArrayList<OrderType> orderTypeLib;
    
    private static OrderTypeLib instance;

    /**
     * Constructor for objects of class OrderTypeLib
     */
    private OrderTypeLib()
    {
        // initialise instance variables
        orderTypeLib = new ArrayList<OrderType>();
    }

    public static OrderTypeLib getOrderTypeLib()
    {
        if(instance == null)
        {
            instance = new OrderTypeLib();
        }
        
        return instance;
    }
    
    public ArrayList<OrderType> getAllOrderTypes()
    {
        // put your code here
        return orderTypeLib;
    }
    
    public OrderType getOrderTypeById(int _orderTypeId)
    {
       OrderType retType = null;
       int index = 0;
       boolean found = false;
       
       while(!found && index < orderTypeLib.size())
       {
           OrderType currOrderType = orderTypeLib.get(index);
           if(currOrderType.getTypeId() == _orderTypeId)
           {
               retType = currOrderType;
               found = true;    
           }
           else
           {
              index++; 
           }
       }
       return retType;
    }
    public void addOrderType(OrderType ot)
    {
        orderTypeLib.add(ot);
    }
}
